#include "UdpSocket.hpp"

int main(int argc, char* argv[]){
  if(argc < 3){
    printf("Which Server do you wanna connect?: [ip] [port]\n");
    return 0;
  }
  UdpSocket cli;
  if(!(cli.CreateSocket())){
    return 1;
  }
  std::string svr_ip = argv[1];
  uint16_t svr_port = atoi(argv[2]);
  while(1){
    std::string send_buf;
    std::cout << "你正在输入: ";
    std::getline(std::cin, send_buf);
    if(!std::cin){
      std::cout << "拜拜了您嘞" << std::endl;
      break;
    }
    fflush(stdin);
    cli.SendTo(send_buf, svr_ip, svr_port);
    std::string recv_buf;
    bool ret = cli.RecevFrom(&recv_buf, &svr_ip, &svr_port);
    if(!ret){
      break;
    }
    std::cout << "服务端回复: " << recv_buf << std::endl;    
    fflush(stdout);
  }
  cli.Close();
  return 0;
}
